package com.jlq.utils;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

//创建日期转换器
public class DateUtil implements Converter<String, Date> {


    public Date convert(String dateStr) {
        System.out.println("接收的日期字符串：" + dateStr);

        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            if(dateStr.contains("T")){
                dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                dateStr = dateStr.replace("T", " ");
            }
            Date date = dateFormat.parse(dateStr);
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
